<script type="text/javascript">
$(document).ready(function(){
	$('#sign-in').validate({
		submitHandler:function(form){
		      $(form).ajaxSubmit({
		        type:'POST',
		        dataType:"json",
		        url:"${url}/user/ajaxLogin?time="+ (new Date()).getTime(),
		        success: function(data){
		        	if(data.result){
		        		location.reload();
		        	}else{
		        		$('.sign-tips').css('height','29px');
						$('.sign-tips').text("错误:"+data.message);
						setTimeout(validateHide, 3000);
		        		return false;
		        	}
		        }
		      });
		},
		rules:{
			email:{
				required: true,
				email:true,
			}
		},
		messages:{
			email: {
				required: "请输入邮箱",
				email:"请输入合法的email地址！"
		    }
		},
		showErrors : function(errorMap, errorList) {  
			var msg = '';  
			$.each(errorList, function(i, v) {  
				msg += (v.message + '\r\n'); 
				return false; 
			});  
			if (msg != '')  
				$('.sign-tips').css('height','29px');
				$('.sign-tips').text(msg);
				setTimeout(validateHide, 3000);
		},  
		/* 失去焦点时不验证 */  
		onfocusout : false  
	});
	
	/**
	 * 退出
	 */
	$('.user-logout').click(function(){
		$.ajax({
			type : "post",
			dataType : "json",
			url : "${url}/user/logout",
			success:function(data){
				if(data){
					location.reload();
				}
			}
		});
	});
	/**
	 * 注册
	 */
	$('#sign-up').validate({
		submitHandler:function(form){
			  //$("input[type='submit']").attr("type","button");
		      $(form).ajaxSubmit({
		      	type:'POST',
		        dataType:"json",
		        url:"${url}/user/ajaxRegist?time="+ (new Date()).getTime(),
		        success: function(data){
		        	if(data.result){
		        		location.reload();
		        	} else {
		        		$('.sign-tips').css('height','29px');
						$('.sign-tips').text(data.message);
						setTimeout(validateHide, 3000);
		        		return false;
		        	}
		        }
		      });
		},
		rules:{
			userName:{
				required: true,
				rangelength: [5,16],
				remote:{
					type:"POST",
					dataType: "json",
					url: "${url}/user/exists?time="+ (new Date()).getTime(),
					data:{key:function(){return $("#registerName").val();}},
					dataFilter: function(data) {
	                    if (data) 
	                        return true;
	                    else
	                        return false;
                	}
				}
			},
			password:{
				required: true,
				rangelength: [6,16]
			},
			confirm_password:{
				required: true,
				rangelength: [6,16],
				equalTo: "#registerPassword"
			},
			email:{
				required: true,
				email:true,
				remote:{
					type:"post",
					url: "${url}/user/emailExists?time="+ (new Date()).getTime(),
					data:{key:function(){return $("#registerEmail").val();}},
					dataType:"json",
					dataFilter: function(data) {
						if (data)
                    		return true;
                    	else
                        	return false;
                	}
				}
			}
		},
		messages:{
			userName:{
				required: "请输入用户名！",
				rangelength: "用户名必须在5-16个字符之间！",
				remote: "用户名存在，不可用！"
			},
			password: {
				required: "请输入密码！",  
				rangelength: "密码必须在6-16个字符之间！"
			},  
			confirm_password: {  
				required: "请输入确认密码！",  
				rangelength: "确认密码必须在6-16个字符之间！", 
				equalTo: "两次输入密码不一致不一致！"  
			},
			email:{
				required: "请输入邮箱！",
				email:"请输入合法的email地址！",
				remote: "邮箱存在，不可用！"
			}
		},
		showErrors : function(errorMap, errorList) {  
			var msg = '';  
			$.each(errorList, function(i, v) {  
				msg += (v.message + '\r\n'); 
				return false; 
			});  
			if (msg != '')  
				$('.sign-tips').css('height','29px');
				$('.sign-tips').text(msg);
				setTimeout(validateHide, 3000);
		},  
		/* 失去焦点时不验证 */  
		onfocusout : false
	});
	
	/**
	 * 找回密码
	 */
	$('#pwd-in').validate({
		submitHandler:function(form){
			  //$("input[type='submit']").attr("type","button");
		      $(form).ajaxSubmit({
		        type:'POST',
		        dataType:"json",
		        url:"${url}/user/findPwd?time="+ (new Date()).getTime(),
		        success: function(data){
		        	alert("找回密码情况已发送到您填写的邮箱中，请查收！");
		        	$("#pwd-in").css('display','none');
		    		$("#pwd-go").css('display','block');
		        }
		      });
		},
		rules:{
			email:{
				required: true,
				email:true
			}
		},
		messages:{
			email:{
				required: "请输入电子邮箱！",
				email:"请输入合法的email地址！",
			}
		},
		showErrors : function(errorMap, errorList) {  
			var msg = '';  
			$.each(errorList, function(i, v) {  
				msg += (v.message + '\r\n'); 
				return false; 
			});  
			if (msg != '')  
				$('.sign-tips').css('height','29px');
				$('.sign-tips').text(msg);
				setTimeout(validateHide, 3000);
		},  
		/* 失去焦点时不验证 */  
		onfocusout : false  
	});
	
	/**
	 * 修改密码
	 */
	$('#pwd-go').validate({
		submitHandler:function(form){
			  $("input[type='submit']").attr("type","button");
		      $(form).ajaxSubmit({
		        type:'POST',
		        dataType:"json",
		        url:"${url}/user/updatePwd?time="+ (new Date()).getTime(),
		        success: function(data){
		        	if(data){
		        		alert("恭喜密码修改成功！");
		        	}else{
		        		alert("密码输入有误请确认或联系管理员");
		        	}
		        	location.reload();
		        }
		      });
		},
		rules:{
			name:{
				required: true
			},
			email:{
				required: true,
				email:true
			}
		},
		messages:{
			name:{
				required: "请输入用户名！",
			},
			email:{
				required: "请输入电子邮箱！",
				email:"请输入合法的email地址！",
			}
		},
		showErrors : function(errorMap, errorList) {  
			var msg = '';  
			$.each(errorList, function(i, v) {  
				msg += (v.message + '\r\n'); 
				return false; 
			});  
			if (msg != '')  
				$('.sign-tips').css('height','29px');
				$('.sign-tips').text(msg);
				setTimeout(validateHide, 3000);
		},  
		/* 失去焦点时不验证 */  
		onfocusout : false  
	});

});
</script>
<div class="sign">
    <div class="sign-mask"></div>
    <div class="containerz">
        <a href="#" class="close-link signclose-loader"><i class="fa fa-close"></i></a>
        <div class="sign-tips"></div>
        <form id="sign-in" style="display: block;" action="#">
            <h3><small class="signup-loader">切换注册</small>登录</h3>
            <h6>
                <label for="email">邮箱</label>
                <input type="text" name="email" id="email" class="form-control" placeholder="登录邮箱">
            </h6>
            <h6>
                <label for="password">密码</label>
                <input type="password" name="password" class="form-control" id="password" placeholder="登录密码">
            </h6>
            <div class="sign-submit">
                <input type="submit" class="btn btn-primary signsubmit-loader" value="登录">
                <label><input type="checkbox" checked="checked" name="rememberMe" value="true">记住我</label>
            </div>
            <div class="sign-info"><a href="javascript:$('#pwd-in').show();$('#sign-in').hide();">找回密码？</a></div>
            <div style="text-align: center;margin-top: 60px;">
	            <span class="other-sign"><a class="qqlogin btn" href="#"><i class="fa fa-qq"></i><span> QQ 登 录</span></a></span>&nbsp;&nbsp;&nbsp;&nbsp;
	            <span class="other-sign"><a class="weibologin btn" href="#"><i class="fa fa-weibo"></i><span> 微博登录</span></a></span>	
            </div>
        </form>
        <form id="pwd-in" style="display: none;" action="#">
            <h3><small class="signin-loader">切换登录</small>找回密码</h3>
            <h6>
                <label for="email">Email</label>
                <input type="text" name="email" class="form-control" id="email" placeholder="注册填写邮箱"></h6>
            <h6>
                <label for="password">用户名</label>
                <input type="text" name="name" id="pwdName" class="form-control" id="password" placeholder="注册填写用户名">
            </h6>
            <div class="sign-submit">
                <input type="submit" class="btn btn-primary signsubmit-loader" value="确认">
            </div>
        </form>
        <form id="sign-up" style="display: none;"> 			            
            <h3><small class="signin-loader">切换登录</small>注册</h3>	
            <h6>			                
                <label for="registerName">用户名</label>			                
                <input type="text" name="userName" class="form-control" id="registerName" placeholder="设置用户名">
            </h6>
            <h6>
                <label for="registerEmail">邮箱</label>
                <input type="email" name="email" class="form-control" id="registerEmail" placeholder="邮箱">
            </h6>
            <h6>
                 <label for="registerPassword">密码</label>
                 <input type="password" name="password" class="form-control" id="registerPassword" placeholder="设置登录密码">
            </h6>
            <h6>
                 <label for="confirm_password">确认密码</label>
                 <input type="password" name="confirm_password" class="form-control" id="confirm_password" placeholder="确认密码">
            </h6>	            
            <div class="sign-submit">			                
                <input type="submit" class="btn btn-primary btn-block signsubmit-loader" name="submit" value="快速注册">
                <input type="hidden" name="action" value="signup">
            </div>
        </form>	
        <form id="pwd-go" style="display: none;"> 			            
            <h3><small class="signin-loader">切换登录</small>注册</h3>	
            <h6>			                
                <label for="ide">密码函</label>			                
                <input type="text" name="ide" class="form-control" id="uName" placeholder="填写密码函">
            </h6>
            <h6>			                
                <label for="name">用户名</label>			                
                <input type="text" name="name" class="form-control" id="uName" placeholder="填写用户名">
            </h6>
            <h6>
                <label for="email">邮箱</label>
                <input type="email" name="email" class="form-control" id="uEmail" placeholder="填写邮箱">
            </h6>
            <h6>
                 <label for="password">新密码</label>
                 <input type="password" name="password" class="form-control" id="uPassword" placeholder="设置登录密码">
            </h6>
            <div class="sign-submit">			                
                <input type="submit" class="btn btn-primary btn-block signsubmit-loader" name="submit" value="Come On">
            </div>
        </form>			    
    </div>			
</div>
